Exception Handling in Java:

Types of exception/errors:
1. syntax: here syntax is wrong. Hence we need to correct it. Syntax exceptions can't be handled using exception handling.


2. logical: here syntax is fine but program is logically wrong. The Logical errors can't be handled using exception handling

Ex: If gender is male & age is 21 -> eligible for marriage
    If gender is female & age is 18 -> eligible for marriage.

if((gender.equals("Male")) && ((age >= 18)))
{
   System.out.println("Male is eligible for marriage");
}else if((gender.equals("Female")) && ((age >= 21)))
{
	System.out.println("Female is eligible for marriage");
}else {
	System.out.println(gender + " is not eligible for marriage");
}

3. runtime: here syntax is fine & the logic is also perfectly fine. But still the programe can fail due to invalid input.
The Runtime Exceptions are those which are arising due to invalid inputs.
We can handle only Runtime Exception. 

Note: In java we can handle only runtime exceptions.

---------------------------------------------------------
The keywords used in exception handling:
1. try
2. catch
3. finally
4. throw
5. thorws


Keywords
1. try: It is a block. It is used to cover the suspecious code. If user thinks that the piece of code might fail, then it should be sorrounded by try block. The exceptions will arise from the try block. If there is a exception in the try block the below lines of code within the try block will never get execute.

2. catch: catch is a block. It should be followed by try block. In catch block we use the exception classes which are similar OR above the exception message class to catch the exception. The catch block will get execute only when there is a exception in the try block.

3. finally: It is a block. It should be followed by either try catch block OR try block alone.
The finally is is also k.a., Default block. Bcoz the finally block will always get execute regardless of exception. Hence we use finally block for writing important code which supposed to execute to all the time regardless of exception.
Ex: Closing the object, releasing the memory etc.

Some time finally block can contain try catch blocks in it especially when you are working with stream objects (read and write operations are part of stream classes).

4. throw: It is used to create OR to raise a customized exception messages. It should be used with any other exception child classes to create a customized exception message.

5. throws: Throws is used at method level especially when the author is not handling the exception within the method and they except user to handle the exception.
throws can have multiple exception classes put together.
--------------------------------------------
There are 2 types of exceptions:
  (1) Unchecked exceptions
  (2) Checked exceptions
  

(1) Unchecked Exception:
If an exception class extends RuntimeException (directly or indirectly), then it is known as an unchecked exception.
In other words, if a program throws an exception that is a child class of RuntimeException, it is termed an unchecked exception.
Unchecked exceptions are not checked at compile time, they are detected at runtime.

Examples: RuntimeException & its child classes
NullPointerException
ArithmeticException
ArrayIndexOutOfBoundsException


(2) Checked Exception:
If an exception class extends Exception but does NOT extend RuntimeException, then it is known as a checked exception.

In other words, if a program throws an exception that is a child class of Exception other than RuntimeException, it is termed a checked exception.

Checked exceptions are checked at compile time, and the compiler forces the programmer to handle them using try-catch or declare them using throws.

Examples: inclusive of Exception & its child classes (except RuntimeException)
IOException
SQLException
ClassNotFoundException

---------------------------------------
Q: What is child exception in java?
Ans: Writing one try block with multiple catch blocks is k.a., Child exception
----------------------------------------
Q: How to create a custom exception classes for your usage in java?
Ans:

